import request from '@/services/http'

// 页面uuid生成
import { v4 as uuidv4 } from 'uuid';

// 火灾检测智能体

// 获取火灾摄像头检测视频流
/* object */
export function getFireVideoFeedcam(data: string) {
  const resp = `${import.meta.env.VITE_API_BASE_URL}/euc/api/fire/camera/feed/${data}?t=${Date.now()}`
  console.log(resp);
  return resp;
}

// 获取火灾摄像头最新检测结果
export const getFireNewCheckcam = async (data: string): Promise<any> => {
  const resp = await request({
    url: `/euc/api/fire/camera/latest/${data}`,
    method: 'GET',
  })
  return resp.data;
}

// 获取火灾检测视频流
/* object */
export function getFireVideoFeed(data:string) {
  const resp = `${import.meta.env.VITE_API_BASE_URL}/euc/api/fire/video/feed/${data}`
  console.log(resp);
  return resp;
}

// 获取火灾最新检测结果
export const getFireNewCheck = async (data: string,bool:boolean): Promise<any> => {
  const resp = await request({
    url: `/euc/api/fire/video/latest/${data}?debug=${bool}`,
    method: 'GET',
  })
  return resp.data;
}


// 病虫害检测智能体

// 获取病虫害摄像头检测视频流
/* object */
export function getDiseaseVideoFeedcam(data: string) {
  const resp = `${import.meta.env.VITE_API_BASE_URL}/euc/api/disease/camera/feed/${data}?t=${Date.now()}`
  console.log('获取病虫害摄像头检测视频流' + resp);
  return resp;
}

// 获取病虫害摄像头最新检测结果
export const getDiseaseNewCheckcam = async (data: string): Promise<any> => {
  const resp = await request({
    url: `/euc/api/disease/camera/latest/${data}`,
    method: 'GET',
  })
  return resp.data;
}

// 获取病虫害检测视频流
/* object */
export function getDiseaseVideoFeed(data:string) {
  const resp = `${import.meta.env.VITE_API_BASE_URL}/euc/api/disease/video/feed/${data}`
  console.log('获取病虫害检测视频流' + resp);
  return resp;
}

// 获取病虫害最新检测结果
export const getDiseaseNewCheck = async (data: string,bool:boolean): Promise<any> => {
  const resp = await request({
    url: `/euc/api/disease/video/latest/${data}?debug=${bool}`,
    method: 'GET',
  })
  return resp.data;
}

// 发送微信消息
export const sendFireWxMeg = async (lelbe: string,conversationId: string): Promise<any> => {
  const resp = await request({
    url: `/euc/api/${lelbe}/chat/history/send/wx/${conversationId}`,
    method: 'POST',
  })
  return resp.data;
}

// 聊天
export const chatQu = async (lelbe: string,data: Object): Promise<any> => {
  const headers = {
    'Content-Type': 'application/json',
    accept: 'text/event-stream',
  }
  const resp = await fetch(`${import.meta.env.VITE_API_BASE_URL}/euc/api/${lelbe}/chat/history/chat`,{
    method: 'POST',
    headers,
    body: JSON.stringify(data),
  })
  return resp;
}

// 保存或更新聊天记录
export const saveChatWxMeg = async (lelbe: string,conversationId: string): Promise<any> => {
  const resp = await request({
    url: `/euc/api/${lelbe}/chat/history/save/${conversationId}`,
    method: 'POST',
  })
  return resp.data;
}

// 获取对话变量
export const getConentMeg = async (lelbe: string,conversationId: string): Promise<any> => {
  const resp = await request({
    url: `/euc/api/${lelbe}/chat/history/variables/${conversationId}`,
    method: 'GET',
  })
  return resp.data;
}

// 分页查询聊天记录
export const chatHistory = async (lelbe: string,conversationId: string): Promise<any> => {
  const resp = await request({
    url: `/euc/api/${lelbe}/chat/history/page?page=1&limit=10000`,
    method: 'GET',
  })
  return resp.data;
}












// 火灾聊天记录
// 保存或更新聊天记录
/*
conversationId
string
{
    "code": 0,
    "message": "string",
    "data": true,
    "result": true
}
 */
export const saveChat = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/fire/chat/history/save/{conversationId}',
    method: 'POST',
    data,
  })
  return resp.data;
}
// 聊天
/*
{
    "query": "string",
    "conversationId": "string",
    "uploadFileId": "string"
}

object
 */
export const chats = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/fire/chat/history/chat',
    method: 'POST',
    data,
  })
  return resp.data;
}

// 获取对话变量
/*
conversationId
string
{
    "code": 0,
    "message": "string",
    "data": {},
    "result": true
}
 */
export const getDialogue = async (): Promise<any> => {
  const resp = await request({
    url: '/euc/api/fire/chat/history/variables/{conversationId}',
    method: 'GET',
  })
  return resp.data;
}

// 分页查询聊天记录
/*
page
integer <int32>
当前页码，从1开始
必需
limit
integer <int32>
每页显示记录数
{
    "code": 0,
    "message": "string",
    "data": {},
    "result": true
}
 */
export const pagingCheckChat = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/fire/chat/history/page',
    method: 'GET',
    data,
  })
  return resp.data;
}
// 删除聊天记录
/*
id
integer <int64>
{
    "code": 0,
    "message": "string",
    "data": true,
    "result": true
}
 */
export const delChat = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/fire/chat/history/{id}',
    method: 'GET',
    data,
  })
  return resp.data;
}

// 火灾摄像头
// 停止火灾检测
/*
{
    "code": 0,
    "message": "string",
    "data": true,
    "result": true
}
 */
export const stopFireCheckcam = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/fire/camera/stop',
    method: 'POST',
    data,
  })
  return resp.data;
}

// 启动火灾检测

/*
rtspUrl
string
{
    "code": 0,
    "message": "string",
    "data": {
        "empty": true,
        "property1": {},
        "property2": {}
    },
    "result": true
}
 */
export const postFireVideocam = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/fire/camera/start',
    method: 'POST',
    data,
  })
  return resp.data;
}




// 病虫害视频
// 停止病虫害检测
/*
{
    "code": 0,
    "message": "string",
    "data": true,
    "result": true
}
 */
export const stopDiseaseCheck = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/disease/video/stop',
    method: 'POST',
    data,
  })
  return resp.data;
}

// 上传视频进行病虫害检测

/*
{
    "video": "string"
}
{
    "code": 0,
    "message": "string",
    "data": {
        "empty": true,
        "property1": {},
        "property2": {}
    },
    "result": true
}
 */
export const postDiseaseVideo = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/disease/video/start',
    method: 'POST',
    data,
  })
  return resp.data;
}

// 病虫害聊天记录
// 保存或更新聊天记录
/*
conversationId
string
{
    "code": 0,
    "message": "string",
    "data": true,
    "result": true
}
 */
export const saveChatdisease = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/disease/chat/history/save/{conversationId}',
    method: 'POST',
    data,
  })
  return resp.data;
}
// 聊天
/*
{
    "query": "string",
    "conversationId": "string",
    "uploadFileId": "string"
}

object
 */
export const chatsdisease = async (data: []): Promise<any> => {
  const resp = await request({
    url: '/euc/api/disease/chat/history/chat',
    method: 'POST',
    data,
  })
  return resp.data;
}

// 获取对话变量
/*
conversationId
string
{
    "code": 0,
    "message": "string",
    "data": {},
    "result": true
}
 */
export const getDialoguedisease = async (): Promise<any> => {
  const resp = await request({
    url: '/euc/api/disease/chat/history/variables/{conversationId}',
    method: 'GET',
  })
  return resp.data;
}

// 分页查询聊天记录
/*
page
integer <int32>
当前页码，从1开始
必需
limit
integer <int32>
每页显示记录数
{
    "code": 0,
    "message": "string",
    "data": {},
    "result": true
}
 */
export const pagingCheckChatdisease = async (): Promise<any> => {
  const resp = await request({
    url: '/euc/api/disease/chat/history/page',
    method: 'GET',
  })
  return resp.data;
}
// 删除聊天记录
/*
id
integer <int64>
{
    "code": 0,
    "message": "string",
    "data": true,
    "result": true
}
 */
export const delChatdisease = async (): Promise<any> => {
  const resp = await request({
    url: '/euc/api/disease/chat/history/{id}',
    method: 'GET',
  })
  return resp.data;
}

// 病虫害摄像头
// 停止病虫害检测
/*
{
    "code": 0,
    "message": "string",
    "data": true,
    "result": true
}
 */
export const stopDiseaseCheckcam = async (): Promise<any> => {
  const resp = await request({
    url: '/euc/api/disease/camera/stop',
    method: 'POST',
  })
  return resp;
}

// 启动病虫害检测

/*
rtspUrl
string
{
    "code": 0,
    "message": "string",
    "data": {
        "empty": true,
        "property1": {},
        "property2": {}
    },
    "result": true
}
 */
export const postDiseaseVideocam = async (data: string): Promise<any> => {
  const resp = await request({
    url: `/euc/api/disease/camera/start?rtspUrl=${data}`,
    method: 'POST',
  })
  return resp.data;
}
